// registerUser.js
const app = getApp()
Page({

  data: {
    infoData:{},
    enterprise: { registerName:'企业名称', name: '法人姓名', identification: '法人身份证号', phone: '法人联系电话', sfzh:'企业代码'},
    spouse: { registerName: '申请人姓名',name: '配偶姓名', identification: '配偶身份证号', phone: '配偶联系电话', sfzh:"申请人身份证号"},

    password:'',
    againPassword:'',
    userType: '',
    identification: '',
    registerPhone: '',
    
    spouseName: '',
    spouseIdentification: '',
    spousePhone: '',

    qylxr: false,
    marriage:false,
    accept:false
  },

  registerChange: function (e) {
    if (e.detail.value === "0") {
      this.setData({
        qylxr: true,
        infoData: this.data.spouse
      })
    }
    if (e.detail.value === '1') {
      this.setData({
        qylxr: false,
        marriage: true,
        infoData: this.data.enterprise
      })
    }
  },
  identification:function(e){

  },
  getPwd:function(e){
    this.setData({
      password: e.detail.value
    });
  },
  provingPwd:function(e){
    var password = this.data.password;
    var provingPwd=e.detail.value;
    if (password != provingPwd || password==''){
      var that=this;
      wx.showModal({
        title: '密码设置错误!',
        content: '密码不能空或俩次输入的密码不一致',
        showCancel:false,
        success: function (res) {
          if (res.confirm) {
            that.setData({
              accept:false,
              password:'',
              againPassword:''
            });
          }
        }
      })
    }
  },
  maritalStatus:function(e){
    wx.setStorageSync('marryStatus', e.detail.value); //婚姻状况
    if (e.detail.value == '0') {
      this.setData({
        marriage: true
      })
    }
    if (e.detail.value == '1') {
      this.setData({
        marriage: false
      })
    }
    if (e.detail.value == '2') {
      this.setData({
        marriage: false
      })
    }
    if (e.detail.value == '3') {
      this.setData({
        marriage: false
      })
    }
  },
  accept:function(e){
    if (e.detail.value == '0') {
      this.setData({
        accept: true
      })
    }else{
      this.setData({
        accept: false
      })
    }
  },
  submit: function (e) {
    var that=this;
    var userType = e.detail.value.userType
    var registerName = e.detail.value.registerName
    var identification = e.detail.value.identification
    var spouseName = e.detail.value.spouseName
    var spouseIdentification = e.detail.value.spouseIdentification
    var spousePhone = e.detail.value.spousePhone
    var address = e.detail.value.address
    var registerPhone = e.detail.value.registerPhone
    var password = e.detail.value.password
    if (userType != "") {
      wx.setStorageSync('userType', userType);
    }
    wx.request({
      url: 'https://www.gcjxglzx.com/userInfo/save',
      method: 'POST',
      data: {
        registerName: registerName,
        userType: userType,
        identification: identification,
        spouseName: spouseName,
        spouseIdentification: spouseIdentification,
        spousePhone: spousePhone,
        address: address,
        registerPhone: registerPhone
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      success: function (res) {
        console.log(res.data)
        if (res.data.status == '0'){
          wx.setStorageSync('identification', identification);
          wx.setStorageSync('password', password)
          wx.navigateTo({
            url: '/page-personalInformationImg/home'
          })
        }
      }
    })
  },

  reset: function (e) {
    this.setData({
      userType: '',
      registerName: '',
      identification: '',
      registerPhone: '',
      address: '',
      spouseName: '',
      spouseIdentification: '',
      spousePhone: '',
    })
    wx.setStorageSync('userType', '')
    wx.setStorageSync('registerName', '')
    wx.setStorageSync('identification', '')
    wx.setStorageSync('registerPhone', '')
    wx.setStorageSync('address', '')
    wx.setStorageSync('spouseName', '')
    wx.setStorageSync('spouseIdentification', '')
    wx.setStorageSync('spousePhone', '')
  },

  onLoad: function (options) {
    this.setData({
      qylxr: true,
      infoData: this.data.spouse
    })
  },

  onReady: function () {

  },

  onShow: function () {

  },


  onHide: function () {

  },

  onUnload: function () {

  },

  onPullDownRefresh: function () {

  },


  onReachBottom: function () {

  },

  onShareAppMessage: function () {

  },

})